package com.yidu.InventoryManagement.mapper;

import com.yidu.InventoryManagement.entity.Cash;
import com.yidu.InventoryManagement.entity.CashStock;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * @author 梁俊
 * @date 2022/12/7
 * &@version 1.0
 */
@Mapper
public interface CashStockMapper {
    /**
     * 分页模糊查现金库存
     * @param map 对象
     * @return Map
     */
    @Select("SELECT c.`DATE`,c.`cashStockId`,f.`fundId`,ca.`cashId`,ca.`accountName`,c.`money`,c.`Remark` FROM cashStock c INNER JOIN cash ca ON ca.`cashId`=c.`cashId` INNER JOIN fund f ON f.`fundId`=c.`fundId` WHERE 1=1 AND ca.`accountName` LIKE #{accountName} AND c.`DATE` LIKE #{DATE} LIMIT #{page},#{limit}")
    public List<CashStock> selectCashStock(Map map);

    /**
     * 查询现金库存id是否为空
     * @return 数量
     */
    @Select("SELECT count(*) FROM cashStock")
    public int selectCashStockIdd();

    /**
     * 根据名字和时间查询现金库存行数
     * @param accountName
     * @param date
     * @return
     */
    @Select("select count(*) from cashStock c INNER JOIN cash ca ON ca.`cashId`=c.`cashId` INNER JOIN fund f ON f.`fundId`=c.`fundId` WHERE 1=1 AND ca.`accountName` LIKE #{accountName} AND c.`DATE` LIKE #{date}")
    public int selectCount(@Param("accountName") String accountName, @Param("date") String date);

    /**
     * 多个删除
     * @param cashStockId 现金库存id
     * @return
     */
    public int deleteCashStock(List cashStockId);


    /**
     * 添加现金库存表
     * @param cashStock
     * @return
     */
     @Insert("INSERT INTO  cashStock VALUES(#{cashStockId},#{fundId},#{cashId},#{date},#{initialState},#{money},#{Remark})")
    public int insertCashStock(CashStock cashStock);



    /**
     * 取现金库存最大的id
     * @return 最大id
     */
    @Select("SELECT cashStockId FROM cashStock ORDER BY cashStockId  DESC LIMIT 1")
    public String selectDa();


    /**
     * 根据id查询现金库存数据
     */
    @Select("select * from cashStock where cashStockId=#{cashStockId}")
    public CashStock selectCashStockId(String cashStockId);


    /**
     * 根据id修改现金库存数据
     */
    @Update("UPDATE cashStock SET fundId=#{fundId},cashId=#{cashId},DATE=#{date},initialState=#{initialState},money=#{money},Remark=#{Remark} where cashStockId=#{cashStockId}")
    public int updateCashStock(CashStock cashStock);

    /**
     * 查询现金账户ID
     */
    @Select("select * from cash LIMIT #{page},#{limit}")
    public List<Cash> selectCash(Map map);

    /**
     * 下拉表格查询现金账户的行数
     */
    @Select("select count(*) from cash")
    public int selectCashCount();
}
